<%@ page language="java"
	import="java.util.*,news.dao.*,news.pojo.*,news.util.*"
	pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'dotopic.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

</head>

<body>
	<%
		request.setCharacterEncoding("utf-8");
		
		//如果操作是修改主题
		try {
			Integer tid = Integer.parseInt(request.getParameter("tid"));
			String tname = request.getParameter("tname");
			Topics t = new Topics();
			t.setTid(tid);
			t.setTname(tname);
			int upresult = TopicDao.td.update(t);
			if (upresult == 1) {
				out.print("<script>alert('成功修改主题！');location='topic_add.jsp';</script>");
				return;
			} else {
				out.print("<script>alert('修改主题失败！');location='topic_add.jsp';</script>");
				return;
			}
		} catch (Exception e) {
		}
		try {
			//如果操作是删除主题
			Integer tid = Integer.parseInt(request.getParameter("deltid"));
			int delresult = TopicDao.td.del(tid);
			if (delresult == 1) {
				out.print("<script>alert('成功删除主题！');location='topic_add.jsp';</script>");
				return;
			} else {
				out.print("<script>alert('删除主题失败！');location='topic_add.jsp';</script>");
				return;
			}
		} catch (Exception e) {
		}
		//增加主题操作
		try {
			String addname = request.getParameter("addname");
			List<Topics> list = TopicDao.td.findAll();
			for (Topics t : list) {
				if (t.getTname().equals(addname)) {
					out.print("<script>alert('增加主题失败！有重复！！');location='topic_add.jsp';</script>");
					return;
				}
				
			}
			int addr= TopicDao.td.add(addname);
				if(addr==1){
				out.print("<script>alert('增加主题成功！！！');location='topic_add.jsp';</script>");
				return;
				}else{
				out.print("<script>alert('增加主题失败！未知错误！！');location='topic_add.jsp';</script>");
				return;
				}
		} catch (Exception e) {
		}
		
	%>
</body>
</html>
